package com.wxxymaker.model.entity;

import com.blade.kit.EncryptKit;
import com.wxxymaker.utils.Base64Util;
import io.github.biezhi.anima.Model;
import io.github.biezhi.anima.annotation.Ignore;
import io.github.biezhi.anima.annotation.Table;

/**
 * @Author: Soft
 * @Date: 2018/6/2 21:18
 * @Desc: 管理员表
 */
@Table(name = "admin")
public class Admin extends Model {
	private Integer id;
	private String  name;
	private String  pass;

	private Integer views;
	@Ignore
	private boolean remember;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	public Integer getViews() {
		return views;
	}

	public void setViews(Integer views) {
		this.views = views;
	}

	public boolean isRemember() {
		return remember;
	}

	public void setRemember(boolean remember) {
		this.remember = remember;
	}

	public String getMd5Np() {
		return Base64Util.encode((this.name + "_" + EncryptKit.md5(this.pass)));
	}

	public static Admin toAdmin(String md5Np) {
		if (md5Np != null) {
			String np = Base64Util.decode(md5Np);
			if (!np.equals("")) {
				String[] nps = np.split("_");
				Admin admin = new Admin();
				admin.setName(nps[0]);
				admin.setPass(nps[1]);
				return admin;
			}
		}
		return null;
	}

	@Override
	public String toString() {
		return "Admin{" +
				"id=" + id +
				", name='" + name + '\'' +
				", pass='" + pass + '\'' +
				", views=" + views +
				", remember=" + remember +
				'}';
	}
}
